/**
 *自定义 Hook函数 动态计算窗口大小
 *
 * @export
 * @param {*} params
 */
import { useState, useEffect } from 'react';
export default function useWinSize() {
    const [width, setWidth] = useState(document.documentElement.clientWidth);
    const [height, setHeight] = useState(document.documentElement.clientHeight);

    const onResize = () => {
        const w = document.documentElement.clientWidth;
        const h = document.documentElement.clientHeight;
        setWidth(w);
        setHeight(h);
    };
    useEffect(() => {
        window.addEventListener('resize', onResize, false);
        return () => {
            window.removeEventListener('resize', onResize, false);
        };
    }, []);

    return { width, height };
}
